package provider

import (
	"OJCenter/global"
	"net/http"
	"net/http/pprof"
)

var Pprof PprofProvider

type PprofProvider struct {
	Mux *http.ServeMux
}

func PprofInit() {
	Pprof = PprofProvider{http.NewServeMux()}
	Start()
}

func Start() error {
	if !global.Conf.PprofProvider.Enable {
		return nil
	}
	Pprof.Mux.HandleFunc("/debug/pprof/", pprof.Index)
	Pprof.Mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
	Pprof.Mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
	Pprof.Mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
	Pprof.Mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
	return http.ListenAndServe(global.Conf.PprofProvider.Addr, Pprof.Mux)
}

func Stop() {
}
